﻿using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _09_1对多
{
    public class OrgUnitConfig : IEntityTypeConfiguration<OrgUnit>
    {
        public void Configure(EntityTypeBuilder<OrgUnit> builder)
        {
            builder.ToTable("T_OrgUnits");
            builder.Property(e => e.Name).HasMaxLength(50).IsRequired().IsUnicode();
            builder.HasOne<OrgUnit>(e => e.Parent).WithMany(e => e.Child); //根节点没有parent,因此要设置成可为空
        }
    }
}
